package telas;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.sample.Plantacao;


public class TelaLogin extends JFrame {
	JPanel panelLogin;
	JLabel labelnome;
	JLabel labelSenha;
	JLabel labelTitulo;
	JButton botaoEntrar;
	JTextField fieldNome;
	JPasswordField fieldSenha;
	final String user = "admin";
	final String password = "123";
	Plantacao plantacao;
	public TelaLogin(final Plantacao plantacao){
		super("iBeans");
		setSize(700,600);
		setLayout(null);
		setResizable(false);
		setLocationRelativeTo(null);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.plantacao = plantacao;
		
		
		labelnome = new JLabel("Digite o nome:");
		labelnome.setBounds(180,30,150,25);
		
		fieldNome = new JTextField();
		fieldNome.setBounds(180, 60, 150, 25);
		
		labelSenha = new JLabel("Digite a senha:");
		labelSenha.setBounds(180, 90, 150, 25);
		
		fieldSenha = new JPasswordField();
		fieldSenha.setBounds(180, 120, 150, 25);
		
		panelLogin = new JPanel();
		panelLogin.setLayout(null);
		panelLogin.setBounds(100, 150, 500, 200);
		panelLogin.setBackground(new Color(205, 186, 150 ));
		
		panelLogin.add(labelnome);
		panelLogin.add(fieldNome);
		panelLogin.add(labelSenha);
		panelLogin.add(fieldSenha);
		
		labelTitulo = new JLabel();
		
		botaoEntrar = new JButton("Entrar");
		botaoEntrar.setBounds(300, 450, 100, 30);
		botaoEntrar.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent e) {}
			public void mousePressed(MouseEvent e){}
			public void mouseExited(MouseEvent e) {
				botaoEntrar.setBackground(null);
				
			}
			public void mouseEntered(MouseEvent e) {
				botaoEntrar.setBackground(new Color(205, 186, 150 ));
				}
			public void mouseClicked(MouseEvent e){
				if(fieldNome.getText().equals(user) && fieldSenha.getText().toString().equals(password)){
					new TelaInicial("Admin", plantacao);
				}
				else{
					JOptionPane.showMessageDialog(null, "Usuario ou Senha errados, por favor tente novamente.");
				}
			}
		});
		
		add(panelLogin);
		add(botaoEntrar);
		setVisible(true);
		
	}
	
	

}
